package com.example.myapplication

import com.bumptech.glide.Glide
import com.example.myapplcation.fragment.BaseActivity
import com.example.myapplication.database.DataBaseUtils
import com.example.total.databinding.ActivityPopularScienceDetailsBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class PopularScienceDetailsMineActivity : BaseActivity<ActivityPopularScienceDetailsBinding>() {
    override fun initData() {
        val id = intent.getLongExtra("id",0L)
        GlobalScope.launch(Dispatchers.IO){
            val data = DataBaseUtils.getInstance(this@PopularScienceDetailsMineActivity).dataBaseDao().queryAllPopularScienceForId(id)
            withContext(Dispatchers.Main){
                data?.run {
                    binding.title.text = name
                    binding.name.text = name
                    Glide.with(this@PopularScienceDetailsMineActivity).load(cover)
                        .into(binding.cover)
                    binding.describe.text = describe
                }
            }
        }
    }
}
